#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> ret;
        if (root == nullptr)
            return ret;
        queue<TreeNode*> q;
        q.push(root);
        while (!q.empty())
        {
            vector<TreeNode*> tmp;
            while (!q.empty())
            {
                tmp.push_back(q.front());
                q.pop();
            }
            vector<int> v;
            for (auto& e : tmp)
            {
                v.push_back(e->val);
                if (e->left)
                    q.push(e->left);
                if (e->right)
                    q.push(e->right);
            }
            ret.push_back(v);
        }
        return ret;
    }
};

class Solution {
public:
    bool _isSymmetricR(TreeNode* left, TreeNode* right)
    {
        if (!left && right || left && !right)
            return false;
        if (left == nullptr && right == nullptr)
            return true;
        if (left->val != right->val)
            return false;
        return _isSymmetricR(left->left, right->right) && _isSymmetricR(left->right, right->left);
    }
    bool isSymmetric(TreeNode* root) {
        return _isSymmetricR(root, root);
    }
};